<template>
	<div class="device-home">
		<div class="device-show">
			<div class="device-title-box">
				<div class="title-box">
					{{$t("homeTitle.hotProducts")}}
				</div>
			</div>
			<div class="device-show2">
				<div class="device-box">
					<div class="device-list" v-for="i in 2" @click="$router.push({path:'/detail'})">
						<div class="imgs">
							<img src="../../../assets/images/device/16492339406107649.jpg" alt="设备">
							<div class="model-box">
								<div class="model">
									<i style="font-size: 35px;color: #fff;" class="el-icon-info"></i>
								</div>
							</div>
						</div>
						<div class="info">
							<div class="titles">
								{{$t("volvoUnit.name")}}
							</div>
							<div class="introduces">
								{{$t("volvoUnit.introduce")}}
							</div>
						</div>
					</div>
					<div class="device-list" v-for="i in 2">
						<div class="imgs">
							<img src="../../../assets/images/device/pjs.webp" alt="设备">
						</div>
						<div class="info">
							<div class="titles">
								{{$t("perkinsUnit.name")}}
							</div>
							<div class="introduces">
								{{$t("perkinsUnit.introduce")}}
							</div>
						</div>
					</div>
					<div class="device-list" v-for="i in 2">
						<div class="imgs">
							<img src="../../../assets/images/device/kms.webp" alt="设备">
						</div>
						<div class="info">
							<div class="titles">
								{{$t("cumminsUnit.name")}}
							</div>
							<div class="introduces">
								{{$t("cumminsUnit.introduce")}}
							</div>
						</div>
					</div>
					<div class="device-list" v-for="i in 2">
						<div class="imgs">
							<img src="../../../assets/images/device/sc.webp" alt="设备">
						</div>
						<div class="info">
							<div class="titles">
								{{$t("upperEngineUnit.name")}}
							</div>
							<div class="introduces">
								{{$t("upperEngineUnit.introduce")}}
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>


<script>
	export default {
		name: "device-home",
		data() {
			return {
				animationKey: 0, // 用于改变关键属性以触发重新渲染
				i: 0
			};
		},
		mounted() {
			window.addEventListener("scroll", this.scrolling);
		},
		methods: {
			scrolling() {
				if (document.querySelector(".title-box")) {
					var titleBox = document.querySelector(".title-box")
					var deviceShow = document.querySelector(".device-show2")
					var img = document.querySelectorAll(".imgs")
					var height = document.documentElement.scrollTop
					// 显示热销产品标题
					if (document.documentElement.scrollTop > 800) {
						titleBox.style.display = "block"
						titleBox.style.animation = "fadeInDown 0.5s linear"
					}
					// 设备显示
					if (document.documentElement.scrollTop > 905) {
						deviceShow.style.display = "block"
						deviceShow.style.animation = "show 1s linear"
						img.forEach((i) => {
							i.style.animation = "show 1s linear"
						})
					}
					// 去除已经执行过的动画
					var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
					var scroll = scrollTop - this.i;
					this.i = scrollTop;
					if (scroll < 0) {
						if (height < 500) {
							titleBox.style.display = "none"
							deviceShow.style.display = "none"
						}
					}
				}
			}
		}
	}
</script>


<style>
	.device-home {
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: rgba(0, 0, 0, 1.0);
	}

	.device-show {
		/* height: 760px; */
	}

	.device-show2 {
		display: none;
	}

	/* 标题 */
	.device-title-box {
		color: #fff;
		height: 165px;
	}

	.title-box {
		font-size: 25px;
		font-weight: 600;
		text-align: center;
		display: none;
		font-size: 48px;
		margin: 0 0 100px 0;
		letter-spacing: 5px;
		font-family: "Ali";
	}

	.device-box {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around
	}

	.device-list {
		width: 280px;
		margin: 0 0 20px 0;
		color: #fff;
		overflow: hidden;
	}

	.device-list:hover img {
		transform: scale(1.1, 1.1);
	}

	.imgs {
		background-color: #fff;
		width: 280px;
		height: 200px;
		overflow: hidden;
		position: relative;
	}

	/* 遮盖层 */
	.model-box {
		opacity: 0;
		transition: 0.5s;
	}

	.model {
		position: absolute;
		z-index: 9999;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: rgba(0, 0, 0, 0.3);
	}

	.device-list:hover .model-box {
		opacity: 1;
	}


	.imgs img {
		width: 280px;
		height: 200px;
		object-fit: cover;
		transition: 0.5s;
	}

	.info {
		padding: 10px;
		background-color: rgba(39, 151, 255, 1.0);
	}

	.titles {
		font-size: 15px;
		font-weight: 600;
		overflow: hidden;
		text-overflow: ellipsis;
		width: 100%;
		white-space: nowrap;
	}

	.introduces {
		font-size: 10px;
		margin: 5px 0 0 0;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}
</style>
